package com.joinway.mobile.client;

import static java.lang.System.out;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import com.joinway.framework.utils.net.HttpClientAdaptor;
import com.joinway.mobile.bean.form.ShopCart;
import com.joinway.mobile.bean.form.OrderForm;


public class AppClient {

	static final HttpClientAdaptor client = new HttpClientAdaptor();
	
	static final String BASE_URL = "http://localhost:8080/jiayida-mobile";
//	static final String BASE_URL = "https://localhost:8443/jiayida-mobile";
//	static final String BASE_URL = "http://115.28.198.131:8000/spring-mobile";
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
//		login();
		addCart();
//		changePassword();
//		logout();
//		Object o = null;
//		Object oo = (Object)o;
//		out.println(oo);
	}

	static void register() throws Exception {
//		RegisterForm form = new RegisterForm();
//		form.setCellPhone("13998429427");
//		form.setName("lee1232");
//		form.setPassword("123456");
////		form.setPassword("654321");
////		form.setUserName("lee1234");
//		
//		client.post(BASE_URL + "/register", form);
//		client.post(BASE_URL + "/register", new PostParameterBuilder().add("name", "lee").add("password", "123").list());
	}

	static void login() throws Exception {
		String json = client.post(BASE_URL + "/login.json", Arrays.asList(
				new NameValuePair[]{
						new BasicNameValuePair("loginName", "lee000")
						, new BasicNameValuePair("password", "123456")
						, new BasicNameValuePair("cellPhoneType", "A")
				})
		);
		
		out.println(json);
	}

	static void remove() throws Exception {
		String json = client.post(BASE_URL + "/baby/cart/remove.json"
				, Arrays.asList(new NameValuePair[]{new BasicNameValuePair("cartId", "1")}));
		out.println(json);
	}

	static void addCart() throws Exception {
		OrderForm form = new OrderForm();
		form.setAddress("address");
		form.setConsignee("lee");
		form.setOrderId("1234567");
		form.setTel("12345678");
		form.setUserId(1);
		form.setZip("123456");
		
		List<ShopCart> carts = new ArrayList<ShopCart>();
		ShopCart cf = new ShopCart();
		cf.setAmount(100);
		cf.setCost(1000);
		cf.setCartId(22);
		carts.add(cf);
		
		form.setCarts(carts);
		client.post(BASE_URL + "/agri/order/add.json", form);
	}

}
